<?php 
header("content-type:text/html;charset=utf8");
$appId = isset($_GET['appId'])?$_GET['appId']:'';
$return = array();
//判断appId是否存在
if (empty($appId)) {
	$return['code'] = 10001;
	$return['data'] = 'Lack of necessary parameters';
}else{
	$pdo = new PDO('mysql:host=123.57.16.97;dbname=project','root','zqVnUy6cxsQXbpEZ');
	$pdo->exec("set names utf8");
	$uid = getUid($pdo,$appId);
	//判断Uid是否存在
	if (empty($uid)) {
		$return['code'] = 10002;
		$return['data'] = 'Logon information does not exist';
	}else{
		$userInfo = getUserInfo($pdo,$uid);
		//判断登录信息是否存在
		if (empty($userInfo)) {
			$return['code'] = 10002;
			$return['data'] = 'Logon information does not exist';
		}else{
			$return['code'] = 10000;
			$return['data'] = $userInfo;
		}
	}
}
echo json_encode($return);

//通过appId获取到相应的登录信息的Uid
function getUid($pdo,$appId){
	$sql = "SELECT uid FROM `relation` WHERE appid = '".$appId."' AND status = 1";
	$uid = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
	return $uid['uid'];
}

//通过uid获取到登录用户的名称和头像
function getUserInfo($pdo,$uid){
	$sql = "SELECT uid,nickname,headimgurl FROM `user` WHERE uid = '$uid'";
	$userInfo = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
	return $userInfo;
}

 ?>
